package com.sskj.mine.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.PwdResetActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;


public class PwdResetActivityPresenter extends BasePresenter<PwdResetActivity> {


    /**
     * 邮箱号重置密码
     *
     * @param pswd   登录密码
     * @param pswd1  确认登录密码
     * @param code   验证码
     * @param mobile 用户账号/邮箱
     * @return
     */
    public void resetPwdWithEmail(String pswd, String pswd1, int code, String mobile) {
        httpService.resetPwdWithEmail(pswd, pswd1, code, mobile)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.resetSuccess();
                        } else {
                            mView.finish();
                        }
                    }
                });
    }

    /**
     * 手机号重置密码
     *
     * @param code    验证码
     * @param pswd    新密码
     * @param account 账号
     * @return
     */
    public void resetPwd(String account, String pswd, String code) {
        httpService.resetPwd(code, pswd, account)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.resetSuccess();
                        } else {
                            mView.finish();
                        }
                    }
                });
    }
}
